﻿@{
    ViewBag.Title = "检查项添加";
}
<style>
    .btn-group {
        margin-top: 0px !important;
        text-align: left !important;
    }
</style>
<div class="container" style="margin-top:30px;margin-bottom:20px">
    <div class="row">
        <form class="form-horizontal bv-form" id="mainForm">
            <div class="col-lg-12 col-sm-12 mb25">
                <div class="form-group ">
                    <label for="parentName" class="col-sm-2 control-label"><em class="required">*</em>类别：</label>
                    <div class="col-sm-8">
                        <input type="text" class="form-control" id="ParentName" name="ParentName" value="" placeholder="请选择类别">
                        <input type="hidden" class="form-control" id="ParentId" name="ParentId" value="">
                        <input type="hidden" class="form-control" id="Level" name="Level" value="">
                    </div>
                </div>
                <div class="form-group ">
                    <label for="name" class="col-sm-2 control-label"><em class="required">*</em>名称：</label>
                    <div class="col-sm-8">
                        <input type="text" class="form-control" name="Name" id="Name" placeholder="请输入名称">
                    </div>
                </div>
                <div class="form-group ">
                    <label for="sort" class="col-sm-2 control-label">排序：</label>
                    <div class="col-sm-8">
                        <input type="text" class="form-control" id="Sort" name="Sort" placeholder="请输入阶段排序">
                    </div>
                </div>
            </div>
            <div class="col-lg-12 col-sm-12 mb25" style="margin-top:57px">
                <div class="col-lg-6 col-sm-6" style="text-align:right">
                    <input type="button" name="submit" id="save" lay-submit lay-filter="sub" value="提&nbsp;&nbsp;&nbsp;交" class="layui-btn layui-btn-small button-base bg-save" />
                </div>
                <div class="col-lg-6 col-sm-6">
                    <input type="button" value="取&nbsp;&nbsp;&nbsp;消" class="cancel layui-btn layui-btn-small button-base bg-cancel ">
                </div>
            </div>
        </form>
    </div>
</div>
<script>
    //选择所属父级
    $("#ParentName").click(function () {
        layer.open({
            type: 2,
            title: GetLayerTitle("检查项-所属父级选择"),
            shadeClose: true, //点击遮罩关闭层
            area: ['500px', '600px'],
            content: '/CheckItem/SelectParent',
        });
    });
    window.onload = function () {
        $('#mainForm').bootstrapValidator({
            excluded: [':hidden'],//[':disabled', ':hidden', ':not(:visible)'] //设置隐藏组件可验证
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                ParentName: {
                    validators: {
                        notEmpty: {
                            message: '父级不能为空'
                        }
                    }
                },
                Name: {
                    validators: {
                        notEmpty: {
                            message: '检查名称不能为空'
                        },
                        stringLength: {
                            max: 100,
                            message: '检查名称不能超过100字符'
                        },
                        regexp: {
                            regexp: /^[a-zA-Z0-9\u4e00-\u9fa5-]+$/i,
                            message: "检查名称由汉字字母数字及-组成"
                        }
                    }
                },
                Sort: {
                    validators: {
                        //notEmpty: {
                        //    message: '排序不能为空'
                        //},
                        stringLength: {
                            max: 10,
                            message: '排序不能超过10字符'
                        }, regexp: {
                            regexp: /^[0-9]+$/i,
                            message: "排序由数字组成"
                        }
                    }
                }
            }
        });
    }
    layui.use(['layer', 'form', 'element', 'laypage'], function () {
        var layer = layui.layer, form = layui.form, element = layui.element, $ = layui.jquery, laypage = layui.laypage;
        //监听提交
        form.on('submit(sub)', function (data) {
            //对表单进行验证
            var bv = $('#mainForm').data('bootstrapValidator');
            bv.validate();
            if (bv.isValid()) {
                var parentId = $("#ParentId").val();
                if (parentId == 0 || parentId == "0") {
                    $("#ParentName").val('');
                }
                var search = $("form").serialize();
                $.post("Add", search, function (data) {
                    if (data.Flag) {
                        parent.layer.msg("添加成功", { time: 1000, icon: 1 }, function () {
                            var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                            parent.layer.close(index);//关闭窗口
                            parent.layer.close(alertIndex);
                        });
                    } else {
                        layer.alert(data.Message, { icon: 2 });
                    }
                });
                return true;
            }
        });
        //关闭弹出iframe层
        $('.cancel').on("click", function () {
            var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
            parent.layer.close(index);//关闭窗口
        });
    });

</script>